package com.example.unitTest;

import com.example.config.modbus.Modbus4jUtils;
import com.example.config.modbus.Modbus4jWriteUtils;
import com.serotonin.modbus4j.ModbusMaster;
import com.serotonin.modbus4j.code.DataType;
import com.serotonin.modbus4j.exception.ErrorResponseException;
import com.serotonin.modbus4j.exception.ModbusInitException;
import com.serotonin.modbus4j.exception.ModbusTransportException;
import org.junit.jupiter.api.Test;

/**
 * @Author 郅占伟
 * @ClassName TestModbus
 * @Description TODO
 * @Date 2024年07月30日
 * @Version: 1.0
 */
public class TestModbus {
    @Test
    public void testModbus() throws ModbusTransportException, ErrorResponseException, ModbusInitException {
        ModbusMaster master = Modbus4jUtils.getMaster("127.0.0.1", 502);

       // Modbus4jWriteUtils.writeHoldingRegister(master, 1, 9, 607, DataType.TWO_BYTE_INT_SIGNED);

        Number numberOne = Modbus4jUtils.readHoldingRegister(master, 1, 9, DataType.TWO_BYTE_INT_SIGNED);
        Number numberTwo = Modbus4jUtils.readHoldingRegister(master, 1, 9, DataType.TWO_BYTE_INT_SIGNED);
        int i = numberOne.intValue();
        int i1 = numberTwo.intValue();
        System.out.println(i);
        System.out.println(i1);
    }
}
